package dao;


import java.math.BigDecimal;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.Date;
import java.util.Collections;
import java.util.List;

import org.apache.commons.lang.ObjectUtils;
import org.apache.torque.TorqueException;
import org.apache.torque.om.BaseObject;
import org.apache.torque.om.ComboKey;
import org.apache.torque.om.DateKey;
import org.apache.torque.om.NumberKey;
import org.apache.torque.om.ObjectKey;
import org.apache.torque.om.SimpleKey;
import org.apache.torque.om.StringKey;
import org.apache.torque.om.Persistent;
import org.apache.torque.util.Criteria;
import org.apache.torque.util.Transaction;


/**
 * This class was autogenerated by Torque on:
 *
 * [Fri Jan 09 02:39:32 PST 2009]
 *
 * You should not use this class directly.  It should not even be
 * extended all references should be to RgepDomain
 */
public abstract class BaseRgepDomain extends BaseObject
{
    /** The Peer class */
    private static final RgepDomainPeer peer =
        new RgepDomainPeer();

        
    /** The value for the rgepdomainid field */
    private int rgepdomainid;
      
    /** The value for the rgepdomaincode field */
    private String rgepdomaincode;
      
    /** The value for the rgepdomainname field */
    private String rgepdomainname;
  
    
    /**
     * Get the Rgepdomainid
     *
     * @return int
     */
    public int getRgepdomainid()
    {
        return rgepdomainid;
    }

                                              
    /**
     * Set the value of Rgepdomainid
     *
     * @param v new value
     */
    public void setRgepdomainid(int v) throws TorqueException
    {
    
                  if (this.rgepdomainid != v)
              {
            this.rgepdomainid = v;
            setModified(true);
        }
    
          
                                  
        // update associated CourseRgepDomain
        if (collCourseRgepDomains != null)
        {
            for (int i = 0; i < collCourseRgepDomains.size(); i++)
            {
                ((CourseRgepDomain) collCourseRgepDomains.get(i))
                    .setRgepdomainid(v);
            }
        }
                      }
  
    /**
     * Get the Rgepdomaincode
     *
     * @return String
     */
    public String getRgepdomaincode()
    {
        return rgepdomaincode;
    }

                        
    /**
     * Set the value of Rgepdomaincode
     *
     * @param v new value
     */
    public void setRgepdomaincode(String v) 
    {
    
                  if (!ObjectUtils.equals(this.rgepdomaincode, v))
              {
            this.rgepdomaincode = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the Rgepdomainname
     *
     * @return String
     */
    public String getRgepdomainname()
    {
        return rgepdomainname;
    }

                        
    /**
     * Set the value of Rgepdomainname
     *
     * @param v new value
     */
    public void setRgepdomainname(String v) 
    {
    
                  if (!ObjectUtils.equals(this.rgepdomainname, v))
              {
            this.rgepdomainname = v;
            setModified(true);
        }
    
          
              }
  
         
                                
            
    /**
     * Collection to store aggregation of collCourseRgepDomains
     */
    protected List collCourseRgepDomains;

    /**
     * Temporary storage of collCourseRgepDomains to save a possible db hit in
     * the event objects are add to the collection, but the
     * complete collection is never requested.
     */
    protected void initCourseRgepDomains()
    {
        if (collCourseRgepDomains == null)
        {
            collCourseRgepDomains = new ArrayList();
        }
    }

    /**
     * Method called to associate a CourseRgepDomain object to this object
     * through the CourseRgepDomain foreign key attribute
     *
     * @param l CourseRgepDomain
     * @throws TorqueException
     */
    public void addCourseRgepDomain(CourseRgepDomain l) throws TorqueException
    {
        getCourseRgepDomains().add(l);
        l.setRgepDomain((RgepDomain) this);
    }

    /**
     * The criteria used to select the current contents of collCourseRgepDomains
     */
    private Criteria lastCourseRgepDomainsCriteria = null;

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getCourseRgepDomains(new Criteria())
     *
     * @throws TorqueException
     */
    public List getCourseRgepDomains() throws TorqueException
    {
        if (collCourseRgepDomains == null)
        {
            collCourseRgepDomains = getCourseRgepDomains(new Criteria(10));
        }
        return collCourseRgepDomains;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this RgepDomain has previously
     * been saved, it will retrieve related CourseRgepDomains from storage.
     * If this RgepDomain is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     *
     * @throws TorqueException
     */
    public List getCourseRgepDomains(Criteria criteria) throws TorqueException
    {
        if (collCourseRgepDomains == null)
        {
            if (isNew())
            {
               collCourseRgepDomains = new ArrayList();
            }
            else
            {
                      criteria.add(CourseRgepDomainPeer.RGEPDOMAINID, getRgepdomainid() );
                      collCourseRgepDomains = CourseRgepDomainPeer.doSelect(criteria);
            }
        }
        else
        {
            // criteria has no effect for a new object
            if (!isNew())
            {
                // the following code is to determine if a new query is
                // called for.  If the criteria is the same as the last
                // one, just return the collection.
                      criteria.add(CourseRgepDomainPeer.RGEPDOMAINID, getRgepdomainid());
                      if (!lastCourseRgepDomainsCriteria.equals(criteria))
                {
                    collCourseRgepDomains = CourseRgepDomainPeer.doSelect(criteria);
                }
            }
        }
        lastCourseRgepDomainsCriteria = criteria;

        return collCourseRgepDomains;
    }

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getCourseRgepDomains(new Criteria(),Connection)
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    public List getCourseRgepDomains(Connection con) throws TorqueException
    {
        if (collCourseRgepDomains == null)
        {
            collCourseRgepDomains = getCourseRgepDomains(new Criteria(10), con);
        }
        return collCourseRgepDomains;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this RgepDomain has previously
     * been saved, it will retrieve related CourseRgepDomains from storage.
     * If this RgepDomain is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    public List getCourseRgepDomains(Criteria criteria, Connection con)
            throws TorqueException
    {
        if (collCourseRgepDomains == null)
        {
            if (isNew())
            {
               collCourseRgepDomains = new ArrayList();
            }
            else
            {
                       criteria.add(CourseRgepDomainPeer.RGEPDOMAINID, getRgepdomainid());
                       collCourseRgepDomains = CourseRgepDomainPeer.doSelect(criteria, con);
             }
         }
         else
         {
             // criteria has no effect for a new object
             if (!isNew())
             {
                 // the following code is to determine if a new query is
                 // called for.  If the criteria is the same as the last
                 // one, just return the collection.
                       criteria.add(CourseRgepDomainPeer.RGEPDOMAINID, getRgepdomainid());
                       if (!lastCourseRgepDomainsCriteria.equals(criteria))
                 {
                     collCourseRgepDomains = CourseRgepDomainPeer.doSelect(criteria, con);
                 }
             }
         }
         lastCourseRgepDomainsCriteria = criteria;

         return collCourseRgepDomains;
     }

                        
              
                    
                    
                                
                                                              
                                        
                    
                    
          
    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this RgepDomain is new, it will return
     * an empty collection; or if this RgepDomain has previously
     * been saved, it will retrieve related CourseRgepDomains from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in RgepDomain.
     */
    protected List getCourseRgepDomainsJoinCourse(Criteria criteria)
        throws TorqueException
    {
        if (collCourseRgepDomains == null)
        {
            if (isNew())
            {
               collCourseRgepDomains = new ArrayList();
            }
            else
            {
                            criteria.add(CourseRgepDomainPeer.RGEPDOMAINID, getRgepdomainid());
                            collCourseRgepDomains = CourseRgepDomainPeer.doSelectJoinCourse(criteria);
            }
        }
        else
        {
            // the following code is to determine if a new query is
            // called for.  If the criteria is the same as the last
            // one, just return the collection.
            boolean newCriteria = true;
                        criteria.add(CourseRgepDomainPeer.RGEPDOMAINID, getRgepdomainid());
                        if (!lastCourseRgepDomainsCriteria.equals(criteria))
            {
                collCourseRgepDomains = CourseRgepDomainPeer.doSelectJoinCourse(criteria);
            }
        }
        lastCourseRgepDomainsCriteria = criteria;

        return collCourseRgepDomains;
    }
                  
                    
                              
                                
                                                              
                                        
                    
                    
          
    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this RgepDomain is new, it will return
     * an empty collection; or if this RgepDomain has previously
     * been saved, it will retrieve related CourseRgepDomains from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in RgepDomain.
     */
    protected List getCourseRgepDomainsJoinRgepDomain(Criteria criteria)
        throws TorqueException
    {
        if (collCourseRgepDomains == null)
        {
            if (isNew())
            {
               collCourseRgepDomains = new ArrayList();
            }
            else
            {
                            criteria.add(CourseRgepDomainPeer.RGEPDOMAINID, getRgepdomainid());
                            collCourseRgepDomains = CourseRgepDomainPeer.doSelectJoinRgepDomain(criteria);
            }
        }
        else
        {
            // the following code is to determine if a new query is
            // called for.  If the criteria is the same as the last
            // one, just return the collection.
            boolean newCriteria = true;
                        criteria.add(CourseRgepDomainPeer.RGEPDOMAINID, getRgepdomainid());
                        if (!lastCourseRgepDomainsCriteria.equals(criteria))
            {
                collCourseRgepDomains = CourseRgepDomainPeer.doSelectJoinRgepDomain(criteria);
            }
        }
        lastCourseRgepDomainsCriteria = criteria;

        return collCourseRgepDomains;
    }
                            


          
    private static List fieldNames = null;

    /**
     * Generate a list of field names.
     *
     * @return a list of field names
     */
    public static synchronized List getFieldNames()
    {
        if (fieldNames == null)
        {
            fieldNames = new ArrayList();
              fieldNames.add("Rgepdomainid");
              fieldNames.add("Rgepdomaincode");
              fieldNames.add("Rgepdomainname");
              fieldNames = Collections.unmodifiableList(fieldNames);
        }
        return fieldNames;
    }

    /**
     * Retrieves a field from the object by name passed in as a String.
     *
     * @param name field name
     * @return value
     */
    public Object getByName(String name)
    {
          if (name.equals("Rgepdomainid"))
        {
                return new Integer(getRgepdomainid());
            }
          if (name.equals("Rgepdomaincode"))
        {
                return getRgepdomaincode();
            }
          if (name.equals("Rgepdomainname"))
        {
                return getRgepdomainname();
            }
          return null;
    }
    
    /**
     * Retrieves a field from the object by name passed in
     * as a String.  The String must be one of the static
     * Strings defined in this Class' Peer.
     *
     * @param name peer name
     * @return value
     */
    public Object getByPeerName(String name)
    {
          if (name.equals(RgepDomainPeer.RGEPDOMAINID))
        {
                return new Integer(getRgepdomainid());
            }
          if (name.equals(RgepDomainPeer.RGEPDOMAINCODE))
        {
                return getRgepdomaincode();
            }
          if (name.equals(RgepDomainPeer.RGEPDOMAINNAME))
        {
                return getRgepdomainname();
            }
          return null;
    }

    /**
     * Retrieves a field from the object by Position as specified
     * in the xml schema.  Zero-based.
     *
     * @param pos position in xml schema
     * @return value
     */
    public Object getByPosition(int pos)
    {
            if (pos == 0)
        {
                return new Integer(getRgepdomainid());
            }
              if (pos == 1)
        {
                return getRgepdomaincode();
            }
              if (pos == 2)
        {
                return getRgepdomainname();
            }
              return null;
    }
     
    /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.
     *
     * @throws Exception
     */
    public void save() throws Exception
    {
          save(RgepDomainPeer.getMapBuilder()
                .getDatabaseMap().getName());
      }

    /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.
       * Note: this code is here because the method body is
     * auto-generated conditionally and therefore needs to be
     * in this file instead of in the super class, BaseObject.
       *
     * @param dbName
     * @throws TorqueException
     */
    public void save(String dbName) throws TorqueException
    {
        Connection con = null;
          try
        {
            con = Transaction.begin(dbName);
            save(con);
            Transaction.commit(con);
        }
        catch(TorqueException e)
        {
            Transaction.safeRollback(con);
            throw e;
        }
      }

      /** flag to prevent endless save loop, if this object is referenced
        by another object which falls in this transaction. */
    private boolean alreadyInSave = false;
      /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.  This method
     * is meant to be used as part of a transaction, otherwise use
     * the save() method and the connection details will be handled
     * internally
     *
     * @param con
     * @throws TorqueException
     */
    public void save(Connection con) throws TorqueException
    {
          if (!alreadyInSave)
        {
            alreadyInSave = true;


  
            // If this object has been modified, then save it to the database.
            if (isModified())
            {
                if (isNew())
                {
                    RgepDomainPeer.doInsert((RgepDomain) this, con);
                    setNew(false);
                }
                else
                {
                    RgepDomainPeer.doUpdate((RgepDomain) this, con);
                }
            }

                                      
                
            if (collCourseRgepDomains != null)
            {
                for (int i = 0; i < collCourseRgepDomains.size(); i++)
                {
                    ((CourseRgepDomain) collCourseRgepDomains.get(i)).save(con);
                }
            }
                          alreadyInSave = false;
        }
      }


                          
      /**
     * Set the PrimaryKey using ObjectKey.
     *
     * @param  rgepdomainid ObjectKey
     */
    public void setPrimaryKey(ObjectKey key)
        throws TorqueException
    {
            setRgepdomainid(((NumberKey) key).intValue());
        }

    /**
     * Set the PrimaryKey using a String.
     *
     * @param key
     */
    public void setPrimaryKey(String key) throws TorqueException
    {
            setRgepdomainid(Integer.parseInt(key));
        }

  
    /**
     * returns an id that differentiates this object from others
     * of its class.
     */
    public ObjectKey getPrimaryKey()
    {
          return SimpleKey.keyFor(getRgepdomainid());
      }

 

    /**
     * Makes a copy of this object.
     * It creates a new object filling in the simple attributes.
       * It then fills all the association collections and sets the
     * related objects to isNew=true.
       */
      public RgepDomain copy() throws TorqueException
    {
        return copyInto(new RgepDomain());
    }
  
    protected RgepDomain copyInto(RgepDomain copyObj) throws TorqueException
    {
          copyObj.setRgepdomainid(rgepdomainid);
          copyObj.setRgepdomaincode(rgepdomaincode);
          copyObj.setRgepdomainname(rgepdomainname);
  
                    copyObj.setRgepdomainid(0);
                        
                                      
                
        List v = getCourseRgepDomains();
        for (int i = 0; i < v.size(); i++)
        {
            CourseRgepDomain obj = (CourseRgepDomain) v.get(i);
            copyObj.addCourseRgepDomain(obj.copy());
        }
                    
        return copyObj;
    }

    /**
     * returns a peer instance associated with this om.  Since Peer classes
     * are not to have any instance attributes, this method returns the
     * same instance for all member of this class. The method could therefore
     * be static, but this would prevent one from overriding the behavior.
     */
    public RgepDomainPeer getPeer()
    {
        return peer;
    }

    public String toString()
    {
        StringBuffer str = new StringBuffer();
        str.append("RgepDomain:\n");
        str.append("Rgepdomainid = ")
           .append(getRgepdomainid())
           .append("\n");
        str.append("Rgepdomaincode = ")
           .append(getRgepdomaincode())
           .append("\n");
        str.append("Rgepdomainname = ")
           .append(getRgepdomainname())
           .append("\n");
        return(str.toString());
    }
}
